/*
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 */
package org.merak.core.configuration.plugin;

public class Provider {

	//~ Attributes ///////////////////////////////////////////////////////////////
	//****************************************************************************
	private String clazz    = null;
	private Object instance = null;

	//~ Constructors /////////////////////////////////////////////////////////////
	//****************************************************************************
	public Provider() {	}

	//****************************************************************************
	public Provider(String clazz) {
		this.clazz = clazz;
	}

	//~ Methods //////////////////////////////////////////////////////////////////
	//****************************************************************************
	public String getClazz() {
		return this.clazz;
	}
	//****************************************************************************
	public void setClazz(String clazz) {
		this.clazz    = clazz;
		this.instance = null;
	}
	//****************************************************************************
	public synchronized Object getInstance()
		   throws ClassNotFoundException, InstantiationException, IllegalAccessException
	{

		if (this.instance == null) {
			this.instance = Class.forName( this.clazz ).newInstance();
		}
		return this.instance;

	}
	//****************************************************************************
	@Override
	public String toString() {
		return this.clazz;
	}
	//****************************************************************************

}
